<template>
	<view class="upphoto-page p-2">
		<view class="p-2 bgcolor1 rounded pb-5">
			<u-upload :fileList="fileList" @afterRead="afterRead" @delete="deletePic" name="file" multiple :maxCount="10"
				:previewFullImage="true" width="200" height="150"></u-upload>
			<view class="mb-2 mt-3"><text class="fs-24 ftcolor1">描述：</text></view>
			<u--textarea height="150" v-model.trim="content" placeholder="请输入内容" placeholderClass="placeholder"></u--textarea>
			<view class="text-white text-center py-1 rounded-circle mt-5 submit"
				:class="isdisabled?'bgcolor7':'bgcolor6'" @click="submit">确定</view>
		</view>
	</view>
</template>

<script>
	import serviceApi from '@/api/serviceApi.js'
	import config from '@/config'
	export default {
		data() {
			return {
				fileList: [],
				content: ''
			}
		},
		computed: {
			isdisabled() {
				return this.fileList.length && this.content
			}
		},
		methods: {
			async afterRead(event) {
				console.log(event)
				let lists = [].concat(event.file)
				lists.map((item) => {
					this.fileList.push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await uni.$tools.uploadFile(
						`${config.api}/api/uni_member/upload`,
						lists[i].url, {
							region_id: uni.getStorageSync('region_id')
						},
					)
					this.fileList.splice(i,1,{
						status: 'success',
						message: '',
						url: result.path
					})
					console.log(result)
				}
			},
			submit(){
				if(!this.isdisabled)return
				serviceApi.gz_ssp_act({img:this.fileList,content:this.content}).then(res => {
					uni.showToast({
						title:res.msg
					})
					setTimeout(() => {
						uni.navigateBack()
					},1500)
				})
			},
			deletePic(event) {
				this.fileList.splice(event.index, 1)
			},
		}
	}
</script>

<style lang="scss">
	.upphoto-page {

	}
</style>